<template>
    <!-- 头部 -->
    <div class="header">
        <div class="fixed">
            <router-link to="/">
                <img class="img" src="../../static/images/logo.png" alt="" />
            </router-link>
            <router-link to="/search">
                <div class="search">
                    <van-search clearable v-model="keyword" shape="round" class="input" focus="true" :placeholder="kw"
                        @clear="clearHandler" />
                </div>
            </router-link>
            <router-link to="/home">
                <van-button class="btn" plain type="default" round size="small">打开APP</van-button>
            </router-link>
        </div>
    </div>

    <!-- tab 中间导航  -->

    <van-tabs v-model:active="active" swipeable color="#f06742" line-width="20px" line-height="3px"
        @click-tab="handler(active)">
        <van-tab v-for="(item, index) in tingList" :key="item.cid" :title="item.title">
        </van-tab>
    </van-tabs>

    <!-- 卡片、图片的数据 -->

    <router-link to="/search">
        <van-card v-for="(item, index) in  danList " :key="danList.id" :price="item.dataCount
            " :title="item.title" :thumb="item.coverPathSmall" :origin-price="item.pageView
        " to="test" />
    </router-link>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import hotApi from '@/api/listen'
import { useRoute, useRouter } from 'vue-router'


// 搜索框value
const keyword = ref('')

// 清空搜索框
const clearHandler = () => {
    keyword.value = ''
}

// 请输入搜索关键词
const kw = ref<any>('')

const active = ref<number>(1)
const route = useRoute()
const router = useRouter()


const pageNum = ref<number>(1)
const pageSize = ref<number>(20)

const tingList = ref<any>([])
const danList = ref<any>([])
const title = ref<any>('remen')
const ttt = ref<any>()


const getCategories = async () => {
    const result = await hotApi.reqCategories()
    // console.log(result);
    tingList.value = result.categories;
}
const getDetail = async () => {
    const result = await hotApi.reqDetail(title.value, pageNum.value, pageSize.value);
    // console.log('D1111', result);
    danList.value = result.subjects

}



const handler = async (index: any) => {
    // console.log(index);
    // console.log(tingList.value[index].name);
    ttt.value = tingList.value[index].name
    const result = await hotApi.reqDetail(ttt.value, pageNum.value, pageSize.value);
    // console.log(result);
    danList.value = result.subjects

}





onMounted(() => {
    getCategories()
    getDetail()
})

</script>

<style scoped lang="scss">
.header {
    display: flex;
    width: 100%;
    height: 50px;
    // border: #f66847 1px solid;
    margin-top: 10px;
    position: relative;

    .fixed {
        position: fixed;
        width: 100%;
        height: 50px;
        top: 0;
        background: #fff;
        z-index: 100;

        .img {
            position: absolute;
            width: 64px;
            height: 14px;
            padding-top: 10px;
            left: 20px;
        }

        .search {
            width: 200px;
            position: absolute;
            top: -6px;
            left: 86px;
        }

        .btn {
            position: absolute;
            border: 1px solid #f66847;
            top: 7px;
            right: 19px;
            color: #f66847;
            height: 28px;
            z-index: 10;
        }
    }
}

.title {
    display: flex;
    height: 25px;
    justify-content: space-between;
    padding-top: 20px;

    .title_msg {
        display: inline-block;
        font-weight: 200;
        line-height: 25px;
        font-family: PingFangSC-Regular;
        color: #40404c;
        font-weight: 400;
        padding-left: 15px;
        font-size: 16px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .more {
        display: inline-block;
        padding-right: 30px;
        font-size: 13px;
        color: #40404c;
        padding-top: 8px;
    }

    .img-more {
        position: absolute;
        height: 15px;
        width: 15px;
        right: 22px;
        top: 26px;
    }
}

.wrap {
    display: flex;
    justify-content: space-evenly;
    position: relative;
    // border: #f66847 1px solid;
    width: 150px;
    height: 50px;

    margin-top: 20px;

    .content_wrap {
        .hearde_img {
            display: inline-block;
            position: absolute;
            left: 10px;
            height: 40px;
            border-radius: 50%;
        }

        .span_name {
            position: absolute;
            display: inline-block;
            top: 3px;
            left: 60px;
            font-weight: 500;
            font-size: 14px;
            color: #40404c;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            margin-right: 4px;
            max-width: 140px;
            width: 100px;
        }

        .span_price {
            position: absolute;
            display: inline-block;
            left: 80px;
            top: 30px;
            font-family: PingFangSC-Regular;
            font-size: 13px;
            color: #a3a3ac;

            .img {
                display: inline-block;
                position: absolute;
                top: -2px;
                left: -21px;
                width: 15px;
                height: 13px;
            }
        }
    }
}

.content {
    display: flex;
    margin-top: 20px;
    width: 400px;
    height: 100px;
    position: relative;

    .content_img {
        position: absolute;
        left: 15px;
        width: 70px;
        height: 70px;
        border-radius: 4px;
    }

    .box {
        display: flex;

        .span1 {
            flex: 1;
            position: absolute;
            left: 100px;
            top: 5px;
            display: inline-block;
            font-size: 16px;
            color: rgb(51, 51, 51);
            overflow: hidden;
            white-space: nowrap;
            -o-text-overflow: ellipsis;
            text-overflow: ellipsis;
            display: inline-block;
            // border: #f66847 solid;
            width: 270px;
        }

        .span2 {
            flex: 0;
            overflow: hidden;
            white-space: wrap;
            -o-text-overflow: ellipsis;
            text-overflow: ellipsis;
            position: absolute;
            left: 100px;
            top: 30px;
            color: #999;
            display: inline-block;
            font-size: 12px;
            word-break: break-all;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            // border: #f66847 solid;
            width: 260px;
            line-height: 18px;
        }

        .icon {
            position: absolute;
            top: 55px;
            left: 200px;
        }

        .img_content {
            position: absolute;
            display: inline-block;
            widows: 12px;
            height: 12px;
            top: 68px;
            left: 100px;
        }

        .name {
            font-size: 12px;
            color: #999;
            display: inline-block;
            position: absolute;
            top: 68px;
            left: 120px;
        }
    }
}

.music {
    width: 400px;
    height: 60px;
    // border: #f66847 solid;
    position: relative;
    margin-top: 20px;
    border-bottom: #eee9e9 solid 1px;

    .music_img {
        width: 50px;
        position: absolute;
        left: 10px;
        border-radius: 50%;
    }

    .music_span {
        position: absolute;
        left: 70px;
        width: 300px;
        top: 5px;
        display: inline-block;
        font-size: 16px;
        color: rgb(51, 51, 51);
        word-break: break-all;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        overflow: hidden;
        white-space: wrap;
        -o-text-overflow: ellipsis;
        text-overflow: ellipsis;
    }

    .music_icon {
        position: absolute;
        top: 30px;
        left: 70px;
        width: 15px;
    }

    .music_name {
        position: absolute;
        left: 90px;
        top: 30px;
        font-size: 12px;
        color: #999;
    }
}

.bg {
    position: relative;
    width: 100%;
    height: 170px;

    .bg_img {
        position: absolute;
        height: 170px;
        width: 100%;
    }

    .bg_tit {
        position: absolute;
        top: 50px;
        left: 160px;
        width: 102px;
        height: 36px;
    }

    .bg_span {
        position: absolute;
        font-size: 12px;
        color: gray;
        font-weight: 400;
        left: 125px;
        top: 100px;
    }
}

.empty {
    height: 110px;

}
</style>
